from string import strip, split
	
files = ["inpainting", "inpainting_major", "inpainting_minor"]

for fileName in files:
	f = open(fileName+".ppm", 'r')
	lines = f.readlines()
	o = open(fileName+"_clean.ppm", 'w')
	o.write(lines[0])
	o.write(lines[1])
	o.write(lines[2])
	lines = [strip(l).split(" ") for l in lines[3:]]
	nums = []
	for line in lines:
		for num in line:
			if num is not '':
				nums.append(num)
	print len(nums)
	
	for i in range(0,len(nums),3):
		o.write("%s %s %s\n" % (nums[i], nums[i+1], nums[i+2]))
	f.close()
	o.close()